package com.example.consult.controller;

import com.example.consult.mapper.SuggestionMapper;
import com.example.consult.model.Suggestion;
import com.example.consult.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Suggestion")
public class SuggestionController {
    @Autowired
    HttpServletRequest request;
    HttpSession session ;

    @Autowired
    SuggestionMapper suggestionMapper;
    @RequestMapping(value = "send",method = RequestMethod.POST)
    @ResponseBody
    public String sendSuggestion(@RequestParam Suggestion suggestion){
        session=request.getSession();
        UserInfo userInfo = (UserInfo) session.getAttribute("User");
        Suggestion suggestion1 = new Suggestion();
        suggestion.setUser_account(userInfo.getUser_account());
        suggestionMapper.insert(suggestion);
        return "ok";
    }
}
